package com.bgs.travelapp.fontRole.service.impl;

import com.bgs.travelapp.fontRole.entity.FontRoleEntity;
import com.bgs.travelapp.fontRole.mapper.fontRoleMapper;
import com.bgs.travelapp.fontRole.service.fontRoleService;
import com.bgs.travelapp.page.MyPageHelper;
import com.bgs.travelapp.page.PageRequest;
import com.bgs.travelapp.page.PageResult;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.awt.*;
import java.util.Iterator;

/**
 * 前端角色管理（后端）
 * gpd 2022-08-29 09点03分
 */
@Service
public class fontRoleServiceImpl implements fontRoleService {

    @Resource
    fontRoleMapper fontRoleMapper;

    /**
     * 新增前端角色
     * 后端---前端角色管理
     * gpd 2022-08-29 09点20分
     * @param fontRoleEntity
     * @return
     */
    @Override
    public Integer saveFontRole(FontRoleEntity fontRoleEntity) {
        fontRoleEntity.setDelFlag(0);
        return fontRoleMapper.insertSelective(fontRoleEntity);
    }

    /**
     *
     * 前端角色分页全查+模糊查（角色名称）
     * gpd 2022-08-29 09点24分
     * @param fontRoleName
     * @return
     */
    @Override
    public PageResult fontRoleByPage(String fontRoleName, PageRequest pageRequest) {
        MyPageHelper.startPage(pageRequest);
        Example example = new Example(FontRoleEntity.class);
        example.createCriteria().andEqualTo("delFlag",0).andLike("fontRoleName","%"+fontRoleName+"%");
        PageResult pageResult = MyPageHelper.pageInfo(fontRoleMapper.selectByExample(example));
        return pageResult;
    }

    /**
     * 前端角色修改
     * gpd 2022-08-29 09点31分
     * @param fontRoleEntity
     * @return
     */
    @Override
    public Integer updateRole(FontRoleEntity fontRoleEntity) {
        return fontRoleMapper.updateByPrimaryKeySelective(fontRoleEntity);
    }

    /**
     * 前端角色删除
     * gpd 2022-08-29 09点34分
     * @param id
     * @return
     */
    @Override
    public Integer deleteRole(Integer id) {
        FontRoleEntity fontRole = new FontRoleEntity();
        fontRole.setDelFlag(1);
        return fontRoleMapper.updateByPrimaryKeySelective(fontRole);
    }
}
